/**
 * Created by luoxiaoming on 16-12-27.
 */
function eval() {
    var patientId = $("#patientId").val();
    if (patientId == null || patientId.length < 4) {
        alert("请输入正确的就诊号");
        return;
    }
    var params = {patientId: patientId}
    $.post("patient/eval", params, function (data) {
        $("#list").empty();
        if (data.failure) {
            $("#deptCode").val("");
            $("#deptName").val("");
            $("#visitCode").val("");
            alert(data.failure);
        } else {
            $("#visitCode").val(data.patientId);
            $("#deptName").val(data.deptName);
            $("#deptCode").val(data.deptCode);
            var detail = data.paper.detail;
            for (var i = 0; i < detail.length; i++) {
                var el = detail[i];
                var innerDiv = '<div style="margin-top: 15px;">' +
                    '<input type="hidden" name="questionId" value="' + el.id + '">' +
                    '<div style="background-color: #e9f2ff">问题：' + el.content + '</div>' +
                    '<div>' +
                    '<table width="100%">' +
                    '<tr>' +
                    '<td><input type="radio" name="question_' + el.id + '" value="A"/>非常不满意</td>' +
                    '</tr>' +
                    '<tr>' +
                    '<td><input type="radio" name="question_' + el.id + '" value="B"/>不满意</td>' +
                    '</tr>' +
                    '<tr>' +
                    '<td><input type="radio" name="question_' + el.id + '" value="C"/>一般</td>' +
                    '</tr>' +
                    '<tr>' +
                    '<td><input type="radio" name="question_' + el.id + '" value="D"/>满意</td>' +
                    '</tr>' +
                    '<tr>' +
                    '<td><input type="radio" name="question_' + el.id + '" value="E"/>非常满意</td>' +
                    '</tr>'+
                    '<tr>' +
                    '<td><input type="text" name="mark_' + el.id + '"/> 其他</td>' +
                    '</tr>' +
                    '</table>' +
                    '</div>' +
                    '</div>';
                var nodeDiv = $(innerDiv);
                $("#list").append(nodeDiv);
                var trs = nodeDiv.find("tr");
                for (var j = 0; j < trs.length; j++) {
                    var tr = trs[j];
                    tr.onmouseover = function () {
                        this.style.background = "#b6bdcc";
                    }
                    tr.onmouseout = function () {
                        this.style.background = "";
                    }
                    // $(tr).unbind('click');
                    $(tr).bind('click', function () {
                        // for (var s = 0; s < trs.length; s++) {
                        //     var tj = trs[s];
                        //     $(tj).find("input[type=radio]").attr("checked", false);
                        // }
                        $(this).parent().find("input[type=radio]").attr("checked", false);
                        $(this).find("input[type=radio]").attr("checked", true);
                    })
                }
            }
        }
    })
}

function submitData() {
    var params = $("#evalForm").serialize();
    $.post("patient/fillQuestions", params, function (data) {
        if (data.failure) {
            alert(data.failure);
            return;
        }else {
            window.location.href="success.jsp"
        }
    });
    return false;
}
